import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.transaction.annotation.Transactional;

import com.persistence.TFootballTeam;
import com.service.CaptainService;
import com.service.PlayerService;
import com.service.TeamService;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:applicationContext.xml" })
@TransactionConfiguration(transactionManager = "txManager", defaultRollback = false)
@Transactional
public class TesServiceTeam {
	Log log = LogFactory.getLog(this.getClass());
	
	@Autowired
	TeamService teamService;
	
	@Autowired
	PlayerService playerService;
	
	@Autowired
	CaptainService captainService;
		
	@Test
	public void insertTeam() {
		TFootballTeam team = new TFootballTeam();
		team.setIdTeam(teamService.countAll()+1);
		team.setTeamName("Bogor FC");
		
		Assert.assertNotNull(teamService.insert(team));
	}
	
	@Test
	public void findTeamById() {
		TFootballTeam team = teamService.findById(1);
		System.out.println(team.getTeamName());
		Assert.assertNotNull(team);
		
	}
	
	@Test
	public void updateTeam() {
		TFootballTeam team = teamService.findById(teamService.countAll());
		team.setTeamName("BOGOR FC");
		Assert.assertNotNull(teamService.update(team));
	}
	
	@Test
	public void removeTeam() {
		TFootballTeam team = teamService.findById(teamService.countAll());
		Assert.assertTrue(teamService.remove(team));
	}
		
	@Test
	public void findAll() {
		List<TFootballTeam> list = teamService.findAll(0);
		Assert.assertNotNull(list);
	}
	
	@Test
	public void countAll() {
		Integer row = teamService.countAll();
		Assert.assertEquals(1l, (long)row);
	}
	
}
